package com.ctrip.ec.biz.dao.payment;
import com.ctrip.ec.biz.entity.payment.PaymentStatus;
import com.ctrip.ec.dal.DaoBase;
import com.ctrip.ec.biz.entity.payment.PaymentEntity;
import com.ctrip.ec.dal.DbAccess;
import com.ctrip.ec.dal.IdConvert;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class PaymentDao extends DaoBase<PaymentEntity> {
    public PaymentDao() {
        super(PaymentEntity.class);
    }
    public PaymentDao(DbAccess db) {
        super(PaymentEntity.class,db);
    }

    public PaymentEntity entityBySn(String sn) throws SQLException {
        String sql = "select * from " + this.getTableName()+ " where sn = ?";
        List<PaymentEntity> list = this.db.query(PaymentEntity.class,sql,sn);
        if(list.size()>0){
            return list.get(0);
        }else{
            return null;
        }
    }

    public void cancel(List<Long> ids) throws SQLException {

        if(ids != null && ids.size()>0) {
            String strIds = IdConvert.join(ids);
            String sql = "update " + this.getTableName() + " set status=" + PaymentStatus.已取消.ordinal() + " where id in (" + strIds + ")";
            this.db.execute(sql);
        }
    }
}
